package com.ywb.controller;

import com.ywb.entity.vo.GalleryBean;
import com.ywb.service.GalleryBeanService;
import com.ywb.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/oss")
public class OssController {
    @Autowired
    private OssService ossService;

    @Autowired
    private GalleryBeanService galleryBeanService;
    @ResponseBody
    @PostMapping("/upload")
    public String uploadOssFile(MultipartFile file){

        String url  = ossService.uploadFileAvatar(file);

//        头像上传成功的时候传入数据库
        GalleryBean galleryBean = new GalleryBean();
        galleryBean.setItemName(file.getOriginalFilename()).setItemSrc(url).setItemClass("images item ");
        galleryBeanService.save(galleryBean);

        return url;
    }
}
